#ifndef GPIO_H
#define GPIO_H


#include <sys/types.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <memory.h>
#include <unistd.h>

#define GPA_addr 0x7F008000 //gpio基地址＝GPACON

#define GPCCON_offset 0x040
#define GPCDAT_offset 0x044
#define GPCPUD_offset 0x048

#define GPKCON1_offset 0x804
#define GPKDAT_offset 0x808
#define GPKPUD_offset 0x80C

#define GPLCON0_offset 0x810
#define GPLCON1_offset 0x814
#define GPLDAT_offset 0x818
#define GPLPUD_offset 0x81C

#define GPMCON_offset 0x820
#define GPMDAT_offset 0x824
#define GPMPUD_offset 0x828

#define GPNCON_offset 0x830
#define GPNDAT_offset 0x834
#define GPNPUD_offset 0x838

#define GPPCON_offset 0x160
#define GPPDAT_offset 0x164
#define GPPPUD_offset 0x168

#define GPQCON_offset 0x180
#define GPQDAT_offset 0x184
#define GPQPUD_offset 0x188

#define GPECON_offset 0x080
#define GPEDAT_offset 0x084
#define GPEPUD_offset 0x088

#define GPOCON_offset 0x140
#define GPODAT_offset 0x144
#define GPOPUD_offset 0x148


#define K8_OUT_on   *GPKDAT |=0x100
#define K8_OUT_off   *GPKDAT &=0xFEFF
#define K9_OUT_on   *GPKDAT |=0x200
#define K9_OUT_off   *GPKDAT &=0xFDFF
#define K10_OUT_on   *GPKDAT |=0x400
#define K10_OUT_off   *GPKDAT &=0xFBFF
#define K11_OUT_on   *GPKDAT |=0x800
#define K11_OUT_off   *GPKDAT &=0xF7FF
#define K12_OUT_on   *GPKDAT |=0x1000
#define K12_OUT_off   *GPKDAT &=0xEFFF
#define K13_OUT_on   *GPKDAT |=0x2000
#define K13_OUT_off   *GPKDAT &=0xDFFF
#define K14_OUT_on   *GPKDAT |=0x4000
#define K14_OUT_off   *GPKDAT &=0xBFFF
#define K15_OUT_on   *GPKDAT |=0x8000
#define K15_OUT_off   *GPKDAT &=0x7FFF

#define L0_OUT_on   *GPLDAT |=0x1
#define L0_OUT_off   *GPLDAT &=0xFFFE
#define L1_OUT_on   *GPLDAT |=0x2
#define L1_OUT_off   *GPLDAT &=0xFFFD
#define L2_OUT_on   *GPLDAT |=0x4
#define L2_OUT_off   *GPLDAT &=0xFFFB
#define L3_OUT_on   *GPLDAT |=0x8
#define L3_OUT_off   *GPLDAT &=0xFFF7
#define L4_OUT_on   *GPLDAT |=0x10
#define L4_OUT_off   *GPLDAT &=0xFFEF
#define L5_OUT_on   *GPLDAT |=0x20
#define L5_OUT_off   *GPLDAT &=0xFFDF
#define L6_OUT_on   *GPLDAT |=0x40
#define L6_OUT_off   *GPLDAT &=0xFFBF
#define L7_OUT_on   *GPLDAT |=0x80
#define L7_OUT_off   *GPLDAT &=0xFF7F

#define  GPC0   (*GPCDAT&0x01)
#define  GPC1   (*GPCDAT&0x02)
#define  GPC2   (*GPCDAT&0x04)
#define  GPC3   (*GPCDAT&0x08)
#define  GPC4   (*GPCDAT&0x10)
#define  GPC5   (*GPCDAT&0x20)
#define  GPC6   (*GPCDAT&0x40)
#define  GPC7   (*GPCDAT&0x80)

#define  GPP1   (*GPPDAT&0x02)
#define  GPP8   (*GPPDAT&0x100)
#define  GPP9   (*GPPDAT&0x200)
#define  GPP12  (*GPPDAT&0x1000)
#define  GPP13  (*GPPDAT&0x2000)



#define bottom_water_level_status 		GPC2		//下水位
#define top_water_level_status 			GPC1		//上水位
#define inter_pressure_switch_status    	GPC7		//夹层压力开关
#define water_switch_status         		GPC6		//水流开关
#define overpressure_protection_switch_status   GPC3	       //超压保护开关
#define front_door_opened_in_place      			GPC0
#define front_door_closed_in_place      			GPC4
#define front_door_Sealing_strip_pressure_in_place     	        GPC5
#define back_door_opened_in_place       			GPP1
#define back_door_closed_in_place       			GPP9
#define back_door_Sealing_strip_pressure_in_place     	        GPP13




#define water_valve_off		         K8_OUT_off				    //加水阀开
#define water_valve_on		         K8_OUT_on			//加水阀关
#define heating_valve_off		 K9_OUT_off				    //加热器开
#define heating_valve_on		 K9_OUT_on			//加热器关
#define Vacuum_pump_off		         K10_OUT_off 			        //真空泵开
#define Vacuum_pump_on		         K10_OUT_on			//真空泵关
#define air_intake_valve_off		 K11_OUT_off			        //进气阀开
#define air_intake_valve_on	         K11_OUT_on			//进气阀关
#define exhaust_valve_off		 K12_OUT_off				    //排气阀开
#define exhaust_valve_on		 K12_OUT_on			//排气阀关
#define air_supply_valve_off		 K13_OUT_off				    //补气阀开
#define air_supply_valve_on	         K13_OUT_on//补气阀关
#define open_front_door                  K14_OUT_on
#define stop_open_front_door             K14_OUT_off
#define close_front_door                 K15_OUT_on
#define stop_close_front_door            K15_OUT_off
#define front_door_Sealing_strip_Inflation             L0_OUT_on
#define stop_front_door_Sealing_strip_Inflation        L0_OUT_off
#define front_door_Sealing_strip_Exhaust               L1_OUT_on
#define stop_front_door_Sealing_strip_Exhaust          L1_OUT_off

#define open_back_door                            L2_OUT_on
#define stop_open_back_door                       L2_OUT_off
#define close_back_door                           L3_OUT_on
#define stop_close_back_door                      L3_OUT_off
#define back_door_Sealing_strip_Inflation         L4_OUT_on
#define stop_back_door_Sealing_strip_Inflation    L4_OUT_off
#define back_door_Sealing_strip_Exhaust           L5_OUT_on
#define stop_back_door_Sealing_strip_Exhaust      L5_OUT_off

#define   SPK_ON    L6_OUT_on
#define   SPK_OFF   L6_OUT_off
#define   LED_ON    L7_OUT_on
#define   LED_OFF   L7_OUT_off

#define LED1_OFF		*GPMDAT|=0x01
#define LED1_ON			*GPMDAT=*GPMDAT&0xFFFE
#define LED2_OFF		*GPMDAT|=0x02
#define LED2_ON			*GPMDAT=*GPMDAT&0xFFFD
#define LED3_OFF		*GPMDAT|=0x04
#define LED3_ON			*GPMDAT=*GPMDAT&0xFFFB
#define LED4_OFF		*GPMDAT|=0x08
#define LED4_ON			*GPMDAT=*GPMDAT&0xFFF7




extern volatile unsigned int* GPCCON;
extern volatile unsigned int* GPCDAT;
extern volatile unsigned int* GPCPUD;

extern volatile unsigned int* GPKCON1;
extern volatile unsigned int* GPKDAT;
extern volatile unsigned int* GPKPUD;

extern volatile unsigned int* GPLCON0;
extern volatile unsigned int* GPLDAT;
extern volatile unsigned int* GPLPUD;
/************led灯测试********/
extern volatile unsigned int* GPMCON;
extern volatile unsigned int* GPMDAT;
extern volatile unsigned int* GPMPUD;


extern volatile unsigned int* GPNCON;
extern volatile unsigned int* GPNDAT;
extern volatile unsigned int* GPNPUD;


extern volatile unsigned int* GPLCON1;
extern volatile unsigned int* GPLDAT;
extern volatile unsigned int* GPLPUD;

extern volatile unsigned int* GPPCON;
extern volatile unsigned int* GPPDAT;
extern volatile unsigned int* GPPPUD;

extern volatile unsigned int* GPQCON;
extern volatile unsigned int* GPQDAT;
extern volatile unsigned int* GPQPUD;

extern volatile unsigned int* GPECON;
extern volatile unsigned int* GPEDAT;
extern volatile unsigned int* GPEPUD;

extern volatile unsigned int* GPOCON;
extern volatile unsigned int* GPODAT;
extern volatile unsigned int* GPOPUD;


extern void GPIO_SETUP();
  // close(fd);
// munmap(GPA_base,1);//解除映射关系


#endif
